/**
  ********************************  STM32F0xx  *********************************
  * @文件名     ： flash.h
  * @作者       ： strongerHuang
  * @库版本     ： V1.5.0
  * @文件版本   ： V1.0.0
  * @日期       ： 2016年06月06日
  * @摘要       ： 内核Flash编程头文件
  ******************************************************************************/

/* 定义防止递归包含 ----------------------------------------------------------*/
#ifndef _FLASH_H
#define _FLASH_H

/* 包含的头文件 --------------------------------------------------------------*/
#include "stm32f0xx.h"


/* 类型定义 ------------------------------------------------------------------*/
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;


//FLASH起始地址
#define STM32_FLASH_BASE 0x08000000 	//STM32 FLASH的起始地址
#define STM32_FLASH_PAGE 16				 	  //STM32 FLASH总页数  16K
 

//FLASH 扇区的起始地址
#define ADDR_FLASH_PAGE_0       ((uint32_t)0x08000000) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_1       ((uint32_t)0x08000400) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_2       ((uint32_t)0x08000800) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_3       ((uint32_t)0x08000C00) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_4       ((uint32_t)0x08000F00) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_5       ((uint32_t)0x08001400) 	// 扇区起始地址, 1 Kbytes 
#define ADDR_FLASH_PAGE_6       ((uint32_t)0x08001800) 	// 扇区起始地址, 1 Kbytes 
#define ADDR_FLASH_PAGE_7       ((uint32_t)0x08001C00) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_8       ((uint32_t)0x08002000) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_9       ((uint32_t)0x08002400) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_10      ((uint32_t)0x08002800) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_11      ((uint32_t)0x08002C00) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_12      ((uint32_t)0x08003000) 	// 扇区起始地址, 1 Kbytes  
#define ADDR_FLASH_PAGE_13      ((uint32_t)0x08003400) 	// 扇区起始地址, 1 Kbytes 
#define ADDR_FLASH_PAGE_14      ((uint32_t)0x08003800) 	// 扇区起始地址, 1 Kbytes 
#define ADDR_FLASH_PAGE_15      ((uint32_t)0x08003C00) 	// 扇区起始地址, 1 Kbytes  
 
 


/* 宏定义 --------------------------------------------------------------------*/
#define FLASH_PAGE_SIZE           ((uint16_t)0x400)         //页大小   - 1K
#define FLASH_TYPE_LENGTH         ((uint16_t)0x002)         //类型大小 - 2字节
#define FLASH_PAGE_LENGTH         (FLASH_PAGE_SIZE/FLASH_TYPE_LENGTH)
#define FLAG_OK                   0x00
#define FLAG_NOOK                 0x01

/* 函数申明 ------------------------------------------------------------------*/
void FLASH_WriteNWord(uint16_t* pBuffer, uint32_t WriteAddr, uint16_t nWord);
void FLASH_ReadNWord(uint16_t* pBuffer, uint32_t ReadAddr, uint16_t nWord);
uint16_t STMFLASH_ReadWord(uint32_t read_addr);
int STMFLASH_Erase(uint32_t EraseAddr, uint32_t NumToErase);
void Flash_writeData(uint32_t addr, uint16_t data);
void FLASH_EraseApp(void);


void U32toU16(uint32_t *Buf32,uint16_t *Buf16,int len);
void U16toU32(uint16_t *Buf16,uint32_t *Buf32,int len);

void U8toU16(uint16_t *Buf16,char *Buf8,int len);
void U16toU8(char *Buf8,uint16_t *Buf16,int len);
int U8mergeU16(uint16_t *Buf16,uint8_t *Buf8,int len);
void U16separateU8(uint8_t *Buf8,uint16_t *Buf16,int len);




#endif /* _FLASH_H */

/**** Copyright (C)2016 strongerHuang. All Rights Reserved **** END OF FILE ****/
